package com.kjj.user.rabbitmq.handler;

import com.kjj.basic.util.SmsUtil;
import com.kjj.user.config.RegisterNoticeRabbitmqConfig;
import com.kjj.user.dto.RegisterNoticeDto;
import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
public class RegisterEmailReceiverHandler {
    @Autowired
    private JavaMailSender javaMailSender;
    @RabbitListener(queues = {RegisterNoticeRabbitmqConfig.QUEUE_INFORM_EMAIL})
    public void receive_email(RegisterNoticeDto registerNoticeDto, Message message, AMQP.Channel channel) {
        System.out.println(registerNoticeDto.getReceiver()+","+
                registerNoticeDto.getContent()+"已经为您发送了邮件请注意查收");
        //send(registerNoticeDto.getReceiver(),registerNoticeDto.getContent());
    }
    public void  send(String phone,String content){
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        //设置发送人
        mailMessage.setFrom("1825799522@qq.com");
        //邮件主题
        mailMessage.setSubject("蓉车宝账号注册");
        //邮件内容
        mailMessage.setText(content);
        //收件人
        mailMessage.setTo(phone+"@163.com");

        javaMailSender.send(mailMessage);
    }
}
